package com.hmdp.config;

import com.hmdp.interceptor.CheckUserLoginInterceptor;
import com.hmdp.interceptor.RefreshTokenExpireInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Autowired
    private CheckUserLoginInterceptor checkUserLoginInterceptor;

    @Autowired
    private RefreshTokenExpireInterceptor refreshTokenExpireInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(refreshTokenExpireInterceptor)
                .addPathPatterns("/**")
                .order(0);

        registry.addInterceptor(checkUserLoginInterceptor)
                .excludePathPatterns(
                        "/user/code",
                        "/user/login",
                        "/shop/**",
                        "/voucher/**",
                        "/voucher-order/**"
                ).order(1);
    }
}
